package org.client.otdr;

import java.util.HashMap;
import java.util.Map;

import org.openems.PrimitiveTraceEntity;
import org.openems.otdr.OtdrSummaryEntities;

import framework.webclient.RestSocket;

public class RemoteMeasurer implements Measurer {

	private RestSocket socket;
//	private RestProperty restProp;

	public RemoteMeasurer(RestSocket httpSocket) {
		this.socket = httpSocket;
	}
	
	@Override
	public void start(String wavelength, String pulsewidth, MeasurerHandler handler) {
		Map<String, String> parameters1 = new HashMap<String, String>();
		parameters1.put("wavelength", wavelength.replace("nm", ""));
		parameters1.put("pulsewidth", pulsewidth.replace("ns", ""));
		OtdrSummaryEntities entities = socket.get("otdrFiles", OtdrSummaryEntities.class, parameters1);
		Map<String, String> parameters2 = new HashMap<String, String>();
		int index = (int)(Math.random() * (double)entities.entities.size());
		parameters2.put("key", entities.entities.get(index).key);
		PrimitiveTraceEntity trace = socket.get("otdrFile", PrimitiveTraceEntity.class, parameters2);
		Double[] ret = trace.y.toArray(new Double[0]);
		handler.onUpdate(ret);
	}

	@Override
	public void stop() {
		// TODO Auto-generated method stub
		
	}

}
